package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.qk.constant.CacheConstants;
import com.qk.domain.business.BusinessCountDO;
import com.qk.domain.clue.ClueCountDO;
import com.qk.management.aop.anno.Cacheable;
import com.qk.management.mapper.BusinessMapper;
import com.qk.management.mapper.ClueMapper;
import com.qk.management.service.ReportOverviewService;
import com.qk.vo.portal.PortalVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 *
 * @author lyl
 * @created 2025/10/15 18:36
 * @description
 *
 */
@Slf4j
@Service
@SuppressWarnings("all")

public class ReportOverviewServiceImpl implements ReportOverviewService {
    private static final String CACHE_PORTAL_KEY_PREFIX = "qk:portal:";

    /*@Autowired
    private StringRedisTemplate redisClient;*/

    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;

    @Cacheable(
            keyPrefix = CacheConstants.CACHE_PORTAL_KEY_PREFIX,
            expireTime = 24*60L,
            expireTimeUnit = TimeUnit.MINUTES
    )
    @Override
    public PortalVO reportOverview() {
        /*String key = CACHE_PORTAL_KEY_PREFIX + "reportOverview";
        try {
            String vlue = redisClient.opsForValue().get(key);
            if (ObjectUtil.isNotEmpty(vlue)){
                PortalVO portalVO = JSONUtil.toBean(vlue, PortalVO.class);
                return portalVO;
            }
        }catch (Exception e){
            log.error("redis查询报表总览异常{}", e.getMessage());
        }*/
        ClueCountDO clueCount = clueMapper.selectCountClue();
        BusinessCountDO businessCount = businessMapper.selectCountBusiness();
        PortalVO portalVO = BeanUtil.copyProperties(clueCount, PortalVO.class);
        BeanUtil.copyProperties(businessCount, portalVO);
        /*try {
            redisClient.opsForValue().set(key, JSONUtil.toJsonStr(portalVO));

        }catch (Exception e){
            log.error("redis保存报表总览异常{}", e.getMessage());
        }*/
        return portalVO;
    }
}
